Skip to content

Use toPythonCopy instead of toPythonProxy in stack and concatenate - #182

Merged
marcelluethi merged 1 commit into
dimwit-dev:mainfrom
marcelluethi:stack-improvements
Nov 18, 2026
Merged

marcelluethi merged 1 commit into
dimwit-dev:mainfrom
marcelluethi:stack-improvements

Conversation

@marcelluethi

Copy link
Copy Markdown
Contributor

stack and concatenate passed their tensors as toPythonProxy. A proxy is a lazy view of the Scala Seq. Every len() call and every element read goes back to the JVM through ScalaPy's JNI bridge. toPythonCopy builds a real Python list in a single conversion. JAX reads it and never has to call back into the JVM.

My measurements have shown a speedup of factor 2-3, which add up for each tensor that is stacked.

stack and concatenate passed their tensors as toPythonProxy. A proxy is a lazy view of the
Scala Seq. Every len() call and every
element read goes back to the JVM through ScalaPy's JNI bridge. toPythonCopy builds a real Python list in a single conversion. Jax reads it and never has to call back into the JVM.
@marcelluethi
marcelluethi merged commit 3bc0a62 into dimwit-dev:main Nov 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants